﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace System.Web.Mvc
{
    public static class DisplayTimeHelper
    {
        public static MvcHtmlString TimePost(this HtmlHelper htmlHelper,DateTime dateTime)
        {
            string strTime = string.Empty;
            TimeSpan timeSpan = DateTime.Now.Subtract(dateTime);
            if (timeSpan.TotalDays > 7)
            {
                strTime = string.Format("{0: HH:mm dd/MM/yyyy}", dateTime);
            }
            else
            {
                if (timeSpan.TotalHours > 23)
                {
                    strTime = string.Format("{0: HH:mm ddd}", dateTime);
                }
                else
                {
                    if (timeSpan.TotalMinutes > 59)
                    {
                        strTime = string.Format("{0} giờ trước", (int)timeSpan.TotalHours);
                    }
                    else
                    {
                        if (timeSpan.TotalMilliseconds > 59)
                        {
                            strTime = string.Format("{0} phút trước", (int)timeSpan.TotalMinutes);
                        }
                        else
                        {
                            strTime = string.Format("{0} giây trước", (int)timeSpan.TotalSeconds);
                        }
                    }
                }
            }
            return new MvcHtmlString( strTime);
        }
    }
}